package com.cloud.tsp.controller;

import com.cloud.api.domain.stats.ArealDistribution;
import com.cloud.api.domain.stats.QueryAreal;
import com.cloud.log.annotation.Log;
import com.cloud.log.enums.BusinessType;
import com.cloud.log.enums.OperatorType;
import com.cloud.mybatis.domain.TableDataInfo;
import com.cloud.tsp.config.MysqlConfig;
import com.cloud.tsp.service.IArealDistributionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import java.io.IOException;

/**
 * <p>
 * OLAP 前端控制器
 * </p>
 *
 * @author haohaibo
 * @since 2023-12-28
 */
@RestController
@RequestMapping("/areal-distribution")
public class ArealDistributionController {

    @Resource
    private IArealDistributionService arealDistributionService;
    @Autowired
    private MysqlConfig mysqlConfig;

    @Tag(name = "v1.0")
    @Operation(summary = "查询区域分布信息（管理）")
    @PostMapping("/getArealDistribution")
    @Log(title = "区域分布管理-查询区域分布信息", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public TableDataInfo<ArealDistribution> selectArealDistribution(@RequestBody @Valid QueryAreal para){
        para.setDataSource(mysqlConfig.getDataSource());
        return arealDistributionService.selectArealDistribution(para);
    }

    @Tag(name = "v1.0")
    @Operation(summary = "区域分布信息导出")
    @PostMapping("/exportArealDistribution")
    @Log(title = "区域分布管理-区域分布信息导出", businessType = BusinessType.EXPORT, operatorType = OperatorType.MANAGE)
    public void exportArealDistribution(QueryAreal para, HttpServletResponse response) throws IOException {
        para.setDataSource(mysqlConfig.getDataSource());
        arealDistributionService.exportArealDistribution(para,response);
    }
}